namespace HexLib
{
    using System;
    using System.ComponentModel;
    using System.Drawing;


    public class StartDateChangedEventArgs : EventArgs
    {
        private DateTime oldTime, newTime;
        public StartDateChangedEventArgs(DateTime oldTime, DateTime newTime)
        {
            this.oldTime = oldTime;
            this.newTime = newTime;
        }

        public DateTime OldTime
        {
            get { return oldTime; }
        }

        public DateTime NewTime
        {
            get { return newTime; }
        }
    }

    public delegate void StartDateChangedEventHandler(object sender, StartDateChangedEventArgs arg);

    public class EndDateChangedEventArgs : EventArgs
    {
        private DateTime oldTime, newTime;
        public EndDateChangedEventArgs(DateTime oldTime, DateTime newTime)
        {
            this.oldTime = oldTime;
            this.newTime = newTime;
        }

        public DateTime OldTime
        {
            get { return oldTime; }
        }

        public DateTime NewTime
        {
            get { return newTime; }
        }
    }

    public delegate void EndDateChangedEventHandler(object sender, EndDateChangedEventArgs arg);

    public class Appointment
    {
        private bool allDayEvent;
        private uint appointmentUID;
        private System.Drawing.Color borderColor = System.Drawing.Color.Blue;
        private System.Drawing.Color color = System.Drawing.Color.White;
        internal int conflictCount;
        private bool drawBorder;
        private DateTime endDate;
        private string group;
        private int layer;
        private bool locked;
        private DateTime startDate;
        private System.Drawing.Color textColor = System.Drawing.Color.Black;
        private string title = "";

        public Appointment()
        {
            this.color = System.Drawing.Color.White;
            this.borderColor = System.Drawing.Color.Blue;
            this.title = "New Appointment";
        }

        public event StartDateChangedEventHandler StartDateChanged;

        public event EndDateChangedEventHandler EndDateChanged;

        private object tag = null;

        public object Tag
        {
            get { return tag; }
            set { tag = value; }
        }

        protected virtual void OnAllDayEventChanged()
        {
        }

        protected virtual void OnBorderColorChanged()
        {
        }

        protected virtual void OnColorChanged()
        {
        }

        protected virtual void OnLockedChanged()
        {
        }

        protected virtual void OnTextColorChanged()
        {
        }

        protected virtual void OnTitleChanged()
        {
        }

        public bool AllDayEvent
        {
            get
            {
                return this.allDayEvent;
            }
            set
            {
                this.allDayEvent = value;
                this.OnAllDayEventChanged();
            }
        }

        public uint AppointmentUID
        {
            get
            {
                return this.appointmentUID;
            }
            set
            {
                this.appointmentUID = value;
            }
        }

        public System.Drawing.Color BorderColor
        {
            get
            {
                return this.borderColor;
            }
            set
            {
                this.borderColor = value;
                this.OnBorderColorChanged();
            }
        }

        public System.Drawing.Color Color
        {
            get
            {
                return this.color;
            }
            set
            {
                this.color = value;
                this.OnColorChanged();
            }
        }

        public bool DrawBorder
        {
            get
            {
                return this.drawBorder;
            }
            set
            {
                this.drawBorder = value;
            }
        }

        public DateTime EndDate
        {
            get
            {
                return this.endDate;
            }
            set
            {
                if (endDate != value)
                {
                    DateTime old = endDate;
                    endDate = value;
                    OnEndDateChanged(old, endDate);
                }
            }
        }

        protected virtual void OnEndDateChanged(DateTime oldTime, DateTime newTime)
        {
            if (EndDateChanged != null)
                EndDateChanged(this, new EndDateChangedEventArgs(oldTime, newTime));
        }

        public string Group
        {
            get
            {
                return this.group;
            }
            set
            {
                this.group = value;
            }
        }

        public int Layer
        {
            get
            {
                return this.layer;
            }
            set
            {
                this.layer = value;
            }
        }

        [DefaultValue(false)]
        public bool Locked
        {
            get
            {
                return this.locked;
            }
            set
            {
                this.locked = value;
                this.OnLockedChanged();
            }
        }

        public DateTime StartDate
        {
            get
            {
                return this.startDate;
            }
            set
            {
                if (startDate != value)
                {
                    DateTime old = startDate;

                    startDate = value;
                    OnStartDateChanged(old, startDate);
                }
            }
        }

        protected virtual void OnStartDateChanged(DateTime oldTime, DateTime newTime)
        {
            if (StartDateChanged != null)
                StartDateChanged(this, new StartDateChangedEventArgs(oldTime, newTime));
        }

        public System.Drawing.Color TextColor
        {
            get
            {
                return this.textColor;
            }
            set
            {
                this.textColor = value;
                this.OnTextColorChanged();
            }
        }

        [DefaultValue("")]
        public string Title
        {
            get
            {
                return this.title;
            }
            set
            {
                this.title = value;
                this.OnTitleChanged();
            }
        }

        private bool alert = false;
        public bool Alert
        {
            get
            {
                return this.alert;
            }
            set
            {
                this.alert = value;
            }
        }
    }
}
